
package org.bridgen.lang.semantics.ast;
import java.util.*;


public class SitePattern extends ASTNode<ASTNode> implements Cloneable {
    public void flushCache() {
        super.flushCache();
    }
     @SuppressWarnings({"unchecked", "cast"})  public SitePattern clone() throws CloneNotSupportedException {
        SitePattern node = (SitePattern)super.clone();
        node.in$Circle(false);
        node.is$Final(false);
    return node;
    }
     @SuppressWarnings({"unchecked", "cast"})  public SitePattern copy() {
      try {
          SitePattern node = (SitePattern)clone();
          if(children != null) node.children = (ASTNode[])children.clone();
          return node;
      } catch (CloneNotSupportedException e) {
      }
      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");
      return null;
    }
     @SuppressWarnings({"unchecked", "cast"})  public SitePattern fullCopy() {
        SitePattern res = (SitePattern)copy();
        for(int i = 0; i < getNumChildNoTransform(); i++) {
          ASTNode node = getChildNoTransform(i);
          if(node != null) node = node.fullCopy();
          res.setChild(node, i);
        }
        return res;
    }
    // Declared in PrettyPrint.jrag at line 200

    
    public void pp(StringBuffer buf) {
    	buf.append("[");
    	for (int i = 0; i < getNumSiteNodeUse(); i++) {
    		getSiteNodeUse(i).pp(buf);
    		if (i != getNumSiteNodeUse()-1) {
    			buf.append(" ");
    		}
    	}
    	buf.append("]");
    }

    // Declared in TypeCodeGen.jrag at line 608

	
	public void generateMethod_possibleSite(String indent, StringBuffer buf) {
		SiteNodeUse prevUse = null;
		for (int i = 0; i < getNumSiteNodeUse(); i++) {
			SiteNodeUse use = getSiteNodeUse(i);
			if (prevUse == null) {
				buf.append(indent + use.getName() + " " + use.getVarName() + " = " + 
					"(node instanceof " + use.getName() + ") ? (" + use.getName() + 
					")node : null;\n");
			} else {
				buf.append(indent + use.getName() + " " + use.getVarName() + " = " +
					"(" + prevUse.getVarName() + " != null && " + prevUse.getVarName() + 
					".getNext() != null) ? (" + use.getName() + ")" + prevUse.getVarName() + 
					".getNext().getNextOfType(" + use.getName() + ".class) : null;\n");
			}
			prevUse = use;
		}
	}

    // Declared in TypeCodeGen.jrag at line 626

	
	public void generateNullCheck(String indent, StringBuffer buf) {
		for (int i = 0; i < getNumSiteNodeUse(); i++) {
			SiteNodeUse use = getSiteNodeUse(i);
			buf.append(use.getVarName() + " != null");
			if (i != getNumSiteNodeUse()-1) {
				buf.append(" && ");
			}
		}
	}

    // Declared in bridgit.ast at line 3
    // Declared in bridgit.ast line 75

    public SitePattern() {
        super();

        setChild(new List(), 0);

    }

    // Declared in bridgit.ast at line 11


    // Declared in bridgit.ast line 75
    public SitePattern(List<SiteNodeUse> p0) {
        setChild(p0, 0);
    }

    // Declared in bridgit.ast at line 15


  protected int numChildren() {
    return 1;
  }

    // Declared in bridgit.ast at line 18

  public boolean mayHaveRewrite() { return false; }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 75
    public void setSiteNodeUseList(List<SiteNodeUse> list) {
        setChild(list, 0);
    }

    // Declared in bridgit.ast at line 6


    private int getNumSiteNodeUse = 0;

    // Declared in bridgit.ast at line 7

    public int getNumSiteNodeUse() {
        return getSiteNodeUseList().getNumChild();
    }

    // Declared in bridgit.ast at line 11


     @SuppressWarnings({"unchecked", "cast"})  public SiteNodeUse getSiteNodeUse(int i) {
        return (SiteNodeUse)getSiteNodeUseList().getChild(i);
    }

    // Declared in bridgit.ast at line 15


    public void addSiteNodeUse(SiteNodeUse node) {
        List<SiteNodeUse> list = getSiteNodeUseList();
        list.addChild(node);
    }

    // Declared in bridgit.ast at line 20


    public void setSiteNodeUse(SiteNodeUse node, int i) {
        List<SiteNodeUse> list = getSiteNodeUseList();
        list.setChild(node, i);
    }

    // Declared in bridgit.ast at line 24

    public List<SiteNodeUse> getSiteNodeUses() {
        return getSiteNodeUseList();
    }

    // Declared in bridgit.ast at line 27

    public List<SiteNodeUse> getSiteNodeUsesNoTransform() {
        return getSiteNodeUseListNoTransform();
    }

    // Declared in bridgit.ast at line 31


     @SuppressWarnings({"unchecked", "cast"})  public List<SiteNodeUse> getSiteNodeUseList() {
        return (List<SiteNodeUse>)getChild(0);
    }

    // Declared in bridgit.ast at line 35


     @SuppressWarnings({"unchecked", "cast"})  public List<SiteNodeUse> getSiteNodeUseListNoTransform() {
        return (List<SiteNodeUse>)getChildNoTransform(0);
    }

    // Declared in PrettyPrint.jrag at line 21
 @SuppressWarnings({"unchecked", "cast"})     public String indent() {
        String indent_value = getParent().Define_String_indent(this, null);
        return indent_value;
    }

public ASTNode rewriteTo() {
    return super.rewriteTo();
}

}
